package my.learn.server.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.HashMap;

@Configuration
@ConditionalOnProperty("spring.datasource.type")
public class DruidConfiguration {


    @Bean
    // 会绑定application.yml 所有spring.datasource开头的配置绑定到DataSource
    @ConfigurationProperties(prefix = "spring.datasource") // 注入全局配置
    public DataSource dataSource() {
        // 方法上添加的熟悉全局注入的注解会作用于 DruidDataSource 类上，并进行自动注入
        return new DruidDataSource();
    }




}
